<template>
  <page-list :x-uri="uri" :custom-components="custom" :x-tabs="tabs" :doactions="doactions">
    <!-- 页面操作按钮 -->
    <template v-slot:page-button>
      <el-button v-auth="'course.offline.create'" size="mini" type="primary" @click="create">新建面授</el-button>
    </template>
  </page-list>
</template>
<script>
import PageList from '@public/template/page_list.vue';
import Status from './components/status';
import UpdateStatus from './components/update_status';

export default {
  components: {
    PageList
  },
  inject: ['reload'],
  data() {
    return {
      uri: 'course/admin/offline/list',
      tabs: [
        {
          title: '面授列表',
          uri: '/course/offline/list',
          meta: {
            permission: 'course.offline.list'
          }
        }
      ],
      custom: {
        status: Status,
        update_status: UpdateStatus
      },
      doactions: [
        { title: '编辑', meta: { permission: 'course.offline.edit' }, callback: this.edit },
        { title: '删除', meta: { permission: 'course.offline.delete' }, callback: this.delete }
      ]
    };
  },
  methods: {
    create: function() {
      this.$router.push({ path: '/course/offline/create' });
    },
    edit: function({ row }) {
      this.$router.push({ path: '/course/offline/' + row.id + '/edit' });
    },
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/course/admin/offline/' + row.id,
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
